package com.zjitc.bookshop39.service.impl;


import com.zjitc.bookshop39.entity.Book;
import com.zjitc.bookshop39.mapper.BookMapper;
import com.zjitc.bookshop39.service.BookService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.mysql.cj.conf.PropertyKey.logger;

/**
*@Author:徐莹
*@Date:2025/04/28 13:30:52
*/

@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookMapper bookMapper;

    /**
     * 查询所有book
     */
    @Cacheable(value = "book", key = "'booklist'")
    @Override
    public List<Book> getBooksList() {
        return  bookMapper.selectAll();
    }
    /**
     * 查询bookById
     */
    @Cacheable(value = "book", key = "'book'+#id")
    @Override
    public Book getBookById(Integer id) {
        return bookMapper.getById(id);
    }
//
//    @Override
//    public Book insertBook(Book book) {
//        return null;
//    }
//
//    @Override
//    public Book editBook(Book book) {
//        return null;
//    }
    /**
     * 删除bookById
     */
    @CacheEvict(value = "book", key = "'book'+#id")
    @Override
    public void delBook(Integer id) {
        bookMapper.delById(id);
    }
}
